<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lựa chọn các segment đi đến được</title>
<script src="jquery-1.7.1.js"></script>
<script type="text/javascript">
$(document).ready(function() { 
	var list_segment_id = "";
	$("#btn_ok").click(function() {
		var str = "";
		var num_checkbox = $("input:checkbox").length;
		for($i = 0; $i < num_checkbox; $i++) {
			var name = $i;
			var temp = 'input[name=' + name + ']';
			if($(temp).is(':checked')) {
				var temp1 = $(temp).val() + ",";
				str += temp1;
			}
		}
		str = str.substring(0, str.lastIndexOf(","));
		opener.document.getElementById('list_segment_id').value = str;
		window.close();	
	});
});
</script>
</head>
	
<body>
	<p>Lựa chọn các segment dưới đây:</p>
	<?php
		include_once "config_db.php";
	
		$database = 'mymap';
		
		if (!mysql_connect($db_host, $db_user, $db_pwd))
		die("Can't connect to database");
		
		if (!mysql_select_db($database))
		die("Can't select database");
		
		mysql_query("SET NAMES 'utf8'");
		
		$table = 'topo_segment';
		$result = mysql_query("SELECT id, name_segment
                            FROM {$table}");
		$i = 0;
		while($data = mysql_fetch_array($result)) {
			echo '<input type="checkbox" name="'.$i.'" value="'.$data["id"].'" />'.$data["name_segment"].' <br/>';
			$i++;
		}
	?>
    <input type="button" value="OK" id="btn_ok" />
</body>
</html>